package com.example.mdm4.ui.home

import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.alibaba.android.arouter.launcher.ARouter
import com.example.mdm4.R
import com.example.mdm4.databinding.FragmentHomeBinding

class HomeFragment : Fragment() {

    private var _binding: FragmentHomeBinding? = null

    // This property is only valid between onCreateView and
    // onDestroyView.
    private val binding get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val homeViewModel =
            ViewModelProvider(this).get(HomeViewModel::class.java)

        _binding = FragmentHomeBinding.inflate(inflater, container, false)
        val root: View = binding.root
/*
        val textView: TextView = binding.tvZx
        homeViewModel.text.observe(viewLifecycleOwner) {
            textView.text = it
        }*/
        val drawable = resources.getDrawable(R.drawable.ic_launcher_background)
        drawable.setBounds(0,0,160,160)
        setImageSize(binding.tvZx,drawable)
        setImageSize(binding.tvBd,drawable)
        setImageSize(binding.tvKq,drawable)
        setImageSize(binding.tvZn,drawable)
        setImageSize(binding.tvGz,drawable)
        setImageSize(binding.tvRw,drawable)
        setImageSize(binding.tvWj,drawable)
        setImageSize(binding.tvWj2,drawable)
        setImageSize(binding.tvWj3,drawable)
        setImageSize(binding.tvLx,drawable)
        setImageSize(binding.tvTl,drawable)
        setImageSize(binding.tvZz,drawable)
        return root
    }

    fun setImageSize(view:TextView,drawable: Drawable){
        view.setCompoundDrawables(null,drawable,null,null)
        view.setOnClickListener {
            if(it.id==R.id.tv_zx){
                ARouter.getInstance().build("/apps/NetAppActivity").navigation()
            }else if (it.id==R.id.tv_wj){
                ARouter.getInstance().build("/doc/DocActivity").navigation()
            }
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}